package com.foreknow.dao.impl;

import com.foreknow.bean.Guestbook;
import com.foreknow.dao.GuestbookDao;
import com.foreknow.mapping.EntityMapping;
import com.foreknow.mapping.MappingFactory;

import java.sql.SQLException;
import java.util.List;

public class GuestbookDaoImpl extends BaseDao implements GuestbookDao {
    @Override
    public boolean add(Guestbook guestbook) throws SQLException {
        int isRigth = jdbcTemplate.update("insert into guestbook(name,phone,email,title,content,createdtime) values(?,?,?,?,?,?)",
                guestbook.getName(),guestbook.getPhone(),guestbook.getEmail(),guestbook.getTitle(),
                guestbook.getContent(),guestbook.getCreatedtime());
        return isRigth == 1;
    }

    @Override
    public List<Object> getAll() {
        EntityMapping entityMapping = mappingFactory.getMapping(MappingFactory.GUESTBOOK_MAPPING);// GuestbookMapping对象
        List<Object> list = jdbcTemplate.query("select * from guestbook",entityMapping);
        return list;
    }

}
